package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/vehicle")
@Slf4j
public class VehicleController {
    @Autowired
    VehicleService vehicleService;

    @GetMapping("select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery) {
        log.debug("查询车辆信息:vehicleQuery={}", vehicleQuery);
        List<VehicleVO> vehicleVOList = vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(vehicleVOList);
    }

    @PostMapping("save")
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam) {
        log.debug("保存车辆信息:vehicleSaveParam={}", vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }

    @DeleteMapping("delete/{id}")
    public JsonResult deleteVehicle(@PathVariable Long id) {
        log.debug("删除车辆信息:id={}", id);
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }

    @PostMapping("unbind/{id}")
    public JsonResult unbindVehicle(@PathVariable Long id) {
        log.debug("车辆解绑围栏:id={}", id);
        vehicleService.unbindVehicle(id);
        return JsonResult.ok();
    }

    @PostMapping("bind/{id}/{geoId}")
    public JsonResult bindVehicle(@PathVariable Long id, @PathVariable Long geoId) {
        log.debug("车辆绑定:id={},geoId={}", id, geoId);
        vehicleService.bindVehicle(id,geoId);
        return JsonResult.ok();
    }
}
